package com.likou;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Author: 陈桂明
 * Date: 2025/3/31 18:53
 * Description: q283
 */
public class q283 {
    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 0, 3, 12};
        new q283().moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }

    public void moveZeroes(int[] nums) {
        if (nums.length == 1) {
            return;
        }
        int left = 0;
        int right = 0;
        int tail = nums.length - 1;

        int zeroNum = 0;
        while (right != nums.length) {
            if (nums[right] != 0) {
                nums[left] = nums[right];
                left++;
            } else {
                zeroNum++;
            }
            right++;
        }

        for (int i = 0; i < zeroNum; i++) {
            nums[tail - i] = 0;
        }
    }
}
